package com.chatSystem;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;

public class ChatView {
    String userName;
    JTextField text;
    JTextArea textArea;
    ClientReadAndPrint.ChatViewListen listener;
    public static JButton jButton1;
    public static JButton jButton2;
    public static JButton jButton3;
    public static JButton jButton;

    //构造函数
    public ChatView(String userName){
        this.userName = userName;
        init();
    }



    public static JButton getXuan(){
        return jButton1;
    }
    public static JButton getTao(){
        return jButton2;
    }
    public static JButton getYuan(){
        return jButton3;
    }
    public static JButton getSend(){
        return jButton;
    }
    void init(){
        JFrame jFrame = new JFrame("客户端");
        jFrame.setBounds(500,200,500,370);
        jFrame.setResizable(false);

        JPanel userPanel = new JPanel();
        JLabel lable = new JLabel("用户:" + userName);
        jButton1 = new JButton("xuan");
        jButton2 = new JButton("tao");
        jButton3 = new JButton("yuan");
        jButton1.setEnabled(false);
        jButton2.setEnabled(false);
        jButton3.setEnabled(false);
        userPanel.add(lable,BorderLayout.NORTH);
        userPanel.add(jButton1,BorderLayout.CENTER);
        userPanel.add(jButton2,BorderLayout.CENTER);
        userPanel.add(jButton3,BorderLayout.CENTER);
        jFrame.add(userPanel);

        JPanel jPanel = new JPanel();

        textArea = new JTextArea("========已登录，欢迎使用========\n",12,35);
        textArea.setEditable(false);

        JScrollPane scroll = new JScrollPane(textArea);  // 滚轮
        scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);  // 显示垂直条

        jPanel.add(lable);
        jPanel.add(scroll);

        text = new JTextField(20);
        jButton = new JButton("发送");

        jPanel.add(text);
        jPanel.add(jButton);


        //设置发送按钮监听
        listener = new ClientReadAndPrint().new ChatViewListen();
        listener.setJTextField(text);
        listener.setJTextArea(textArea);
        listener.setChatViewJf(jFrame);
        text.addActionListener(listener);  // 文本框添加监听
        jButton.addActionListener(listener);  // 按钮添加监听
        jButton1.addActionListener(listener);
        jButton2.addActionListener(listener);
        jButton3.addActionListener(listener);

        jFrame.add(jPanel);
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jFrame.setVisible(true);
        jFrame.add(userPanel, BorderLayout.NORTH);

    }

}
